<?php include('./templete/public/head.php')?>
<body>
<hr class="bgcolor" />
<!--评估-->
<div class="assess-main">
    <div class="assess-content ">
        <form class="myform">
        <div class="c-top">
            <ul class="comm-table-view">
                <li class="table-view-cell table-view-cell2">
                    <a>
                        <span>评估事项</span>
                        <div class="top-text text1">
                            <?php echo $rows['problem_content']?>
                        </div>
                    </a>
                </li>
                <li class="table-view-cell table-view-cell2">
                    <a>
                        <span>理由</span>
                        <div class="top-text text2">
                            <textarea name="adopt_reason"><?php echo $rows['adopt_reason']?></textarea>
                        </div>
                    </a>
                </li>
                <li class="table-view-cell table-view-cell2">
                    <a>
                        <span>改善方案</span>
                        <div class="top-text text2">
                            <textarea name="improve_content"><?php echo $rows['improve_content']?></textarea>
                        </div>
                    </a>
                </li>
            </ul>
        </div>
        <hr class="bgcolor" />

            <div class="fabu-main fabu-idea-main">
                <div class="main-content">
                    <div class="c-list">
                            <ul class="comm-table-view">
                                <li class="table-view-cell">
                                    <a>
                                        <span class="title">实施改善（部门）</span>
                                        <span class="line">|</span>
                                        <span class="input" id="showDepartPicker">
                                        <input type="text" name="department" id="departName" value="<?php echo $rows['department']?>" placeholder="" readonly/></span>
                                        <input type="hidden" name="departid" id="departid" value="<?php echo $rows['departid']?>" placeholder="" readonly/></span>
                                        <span class="fr"><i class="iconfont icon-youjiantou"></i></span>
                                    </a>
                                </li>

                                <li class="table-view-cell">
                                    <a>
                                        <span class="title">请选择分类</span>
                                        <span class="line">|</span>
                                        <span class="input" id="showClassPicker">
                                <input type="text" name="question_classfy" id="className" value="<?php echo $rows['question_classfy']?>" placeholder="" readonly/>
                                <input type="hidden" name="question_classfyid" id="question_classfyid" value="<?php echo $rows['question_classfyid']?>" placeholder="" readonly/>
                            </span>
                                        <span class="fr"><i class="iconfont icon-youjiantou"></i></span>
                                    </a>
                                </li>
                                <li class="table-view-cell">
                                    <a>
                                        <span class="title">完成方式</span>
                                        <span class="line">|</span>
                                        <span class="input" id="showModePicker">
                                        <input type="text"  id="modeName" value="<?php switch($rows['complete_type']){
                                            case 1:
                                                echo '我提你改';
                                                break;
                                            case 2:
                                                echo '自提自改';
                                                break;
                                            case 3:
                                                echo '寻求合作';
                                                break;
                                        }?>" placeholder="" readonly/></span>
                                        <input type="hidden" name="complete_type" id="complete_type" value="<?php echo $rows['complete_type']?>"  readonly/></span>
                                        <span class="fr"><i class="iconfont icon-youjiantou"></i></span>
                                    </a>
                                </li>

                            </ul>
                    </div>
                </div>
            </div>
        <div class="c-bot">
            <ul class="comm-table-view">
                <li class="table-view-cell">
                    <a>
                        <span>完成时间</span>
                        <span class="input "><input type="text" name="hope_time" id="result" value="<?php echo $rows['hope_time']?>" /></span>
                    </a>
                </li>
                <li class="table-view-cell zhiding">
                    <a id="showUserPicker">
                        <span>指定人员</span>
                        <span class="fr user_name_list"><?php if($rows['complete_type']==2){echo $rows['user_name'];}?></span>
                        <input type="hidden" id="complete_user_id" name="complete_user_id" value="<?php if($rows['complete_type']==2){echo $rows['user_id'];}?>">
                        <input type="hidden" id="complete_user_name" name="complete_user_name" value="<?php if($rows['complete_type']==2){echo $rows['user_name'];}?>">
                    </a>
                </li>

            </ul>
        </div>
            <input type="hidden" name="id" value="<?php echo $rows['id']?>">
        </form>
        <div class="comm-btn assess-btn">
            <span class="color1 adopt">采纳</span>
            <span class="color2 unadopt">不采纳</span>
        </div>
    </div>
</div>
<script src="_js/plug/mui.picker.all.js"></script>
<?php include('./templete/public/script.php')?>
</body>
<script>
    mui.init({
        swipeBack: true //启用右滑关闭功能
    });
    //采纳
    $('.adopt').click(function () {
        var param =$('.myform').serializeArray();
        var complete_type =$('#complete_type').val();
        if((!complete_type)||(complete_type==0)){
            layer.msg('请选择完成类型');
            return false;
        }
        console.log(complete_type);
        var question_classfyid =$('#question_classfyid').val();
        if((!question_classfyid)||(question_classfyid==0)){
            layer.msg('请选择问题分类');
            return false;
        }
        <?php if(($rows['complete_type']==1)&&(in_array($rows['status'],[1,5,7]))){?>
        var complete_user = $('#complete_user_name').val();
        if(!complete_user){
            layer.msg('因提议完成类型为你提我改，请指定完成人员');
            return false;
        }
        <?php }?>
        let loading = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
        $.ajax({
            url:'<?php echo url('jdz/adopt',['adopt'=>1])?>',
            data:param,
            type:'post',
            success:function (data) {
                layer.closeAll();
                if(data.code==1){
                    layer.msg(data.msg);
                    setTimeout(function () {
                        location.href = '/index/jdz/detail/id/'+'<?php echo $rows['id']?>';
                    },1000)
                }else{
                    layer.msg(data.msg);
                }
            }
        })
    });
    //不采纳
    $('.unadopt').click(function () {
        var param =$('.myform').serializeArray();
        let loading = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
        $.ajax({
            url:'<?php echo url('jdz/adopt',['adopt'=>2])?>',
            data:param,
            type:'post',
            success:function (data) {
                layer.closeAll();
                if(data.code==1){
                    layer.msg(data.msg);
                    setTimeout(function () {
                        location.href = '/index/jdz/detail/id/'+'<?php echo $rows['id']?>';
                    },1000)
                }else{
                    layer.msg(data.msg);
                }
            }
        })
    });
    $(function() {
        $("#result").click(function() {
            var dtPicker = new mui.DtPicker({
                type: 'date'
            });
            dtPicker.show(function(selectItems) {
                var y = selectItems.y.text; //获取选择的年
                var m = selectItems.m.text; //获取选择的月
                var d = selectItems.d.text; //获取选择的日
                var date = y + "-" + m + "-" + d;
                $("#result").val(date);
            })
        });
    })
    $('#showUserPicker').click(function () {
        var complete_user_id = $('#complete_user_id').val();
        console.log(complete_user_id);
        complete_user_id = complete_user_id.split(',');
        console.log(complete_user_id);
        select_entercontact('multi','user',complete_user_id,'user');
    });
    $('#showDepartPicker').on('click',function () {
        select_entercontact('single','department',[],'department');
    })
    function select_entercontact(mode,type,_partners_id,cases){
        wx.invoke("selectEnterpriseContact", {
                "fromDepartmentId": -1,// 必填，表示打开的通讯录从指定的部门开始展示，-1表示自己所在部门开始, 0表示从最上层开始
                "mode": mode,// 必填，选择模式，single表示单选，multi表示多选
                "type": [type],// 必填，选择限制类型，指定department、user中的一个或者多个
                "selectedDepartmentIds": ["<?php echo $rows['departid']?>"],// 非必填，已选部门ID列表。用于多次选人时可重入，single模式下请勿填入多个id
                "selectedUserIds": _partners_id// 非必填，已选用户ID列表。用于多次选人时可重入，single模式下请勿填入多个id
            },function(res){
                if (res.err_msg == "selectEnterpriseContact:ok")
                {
                    if(typeof res.result == 'string')
                    {
                        res.result = JSON.parse(res.result) //由于目前各个终端尚未完全兼容，需要开发者额外判断result类型以保证在各个终端的兼容性
                    }
                    var selectedUserList = res.result.userList; // 已选的成员列表
                    var userId=Array();
                    var userName=Array();
                    var userAvatar=Array();
                    var departmentId =Array();
                    var departemntName =Array();
                    var selectedDepartmentList = res.result.departmentList;// 已选的部门列表
                    for (var i = 0; i < selectedDepartmentList.length; i++)
                    {
                        var department = selectedDepartmentList[i];
                        departmentId[i] = department.id;// 已选的单个部门ID
                        departemntName[i] = department.name;// 已选的单个部门名称
                    }
                    for (var i = 0; i < selectedUserList.length; i++)
                    {
                        var user = selectedUserList[i];
                        userId[i] = user.id; // 已选的单个成员ID
                        userName[i] = user.name;// 已选的单个成员名称
                        userAvatar[i]= user.avatar;// 已选的单个成员头像
                    }
                    if(cases=='user') {
                        $(".user_name_list").html(userName);
                        $("#complete_user_id").val(userId);
                        $("#complete_user_name").val(userName);
                    }
                    if(cases == 'department'){
                        $('#departName').val(departemntName);
                        $('#departid').val(departmentId);
                    }
                }
            }
        );
    }
    var subinvman_sel3 = $("#showClassPicker");//请选择分类
    var subinvman_sel4 = $("#showModePicker");//完成方式
    if (subinvman_sel3) {
        var picker3 = new mui.PopPicker();
        picker3.setData([{value: '1', text: '产品质量'}, {value: '2', text: '产品成本'}, {value: '3', text: '产品性能'}
            ,{value: '4', text: '标准作业程序'}, {value: '5', text: '工作流程'}, {value: '6', text: '设备'}
            ,{value: '7', text: '设施'}, {value: '8', text: '物料储运'}, {value: '9', text: '环境、健康、安全'}
            ,{value: '10', text: '食堂及伙食'}, {value: '11', text: '其他'}
        ]);
        document.querySelector("#showClassPicker").addEventListener("tap", function () {
            picker3.show(function (items) {
                $("#className").val(items[0].text);
                $("#question_classfyid").val(items[0].value);

            });
        });
    }
    if (subinvman_sel4) {
        var picker4 = new mui.PopPicker();
        //picker4.setData([{value: '1', text: '我提你改'}, {value: '2', text: '自提自改'}, {value: '3', text: '寻求合作'}]);
		picker4.setData([{value: '1', text: '我提你改'},{value: '3', text: '寻求合作'}]);
        document.querySelector("#showModePicker").addEventListener("tap", function () {
            picker4.show(function (items) {
                console.log(items[0].text)
                $("#modeName").val(items[0].text);
                $("#complete_type").val(items[0].value);
                if (items[0].value == 3) {
                    $('.partner').show();
                } else {
                    $('.partner').hide();
                }

            });
        });
    }
</script>

</html>